package com.ai.app.controller;

import org.springframework.ai.chat.messages.SystemMessage;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping;
import reactor.core.publisher.Flux;

@RequestMapping("/ds")
@RestController
public class DeepSeekController {

//    @Autowired
//    private RequestMappingHandlerMapping handlerMapping;
//
//    // 新增接口：查看所有已注册的请求路径
//    @RequestMapping("/mappings")
//    public String showMappings() {
//        // 遍历所有映射，拼接成字符串返回
//        StringBuilder mappings = new StringBuilder();
//        handlerMapping.getHandlerMethods().forEach((key, value) -> {
//            mappings.append(key).append("\n");
//        });
//        return mappings.toString();
//    }
    @Autowired
    private OpenAiChatModel chatModel;

    @RequestMapping("/chat")
    public String chat(String message){
        return  chatModel.call(message);
    }

    @RequestMapping("/chatByPrompt")
    public String chatByPrompt(String message){
        Prompt prompt = new Prompt(message);
        ChatResponse response = chatModel.call(prompt);
        return response.getResult().getOutput().getText();
    }
//
//    @RequestMapping("/role")
//    public String role(String message){
//        SystemMessage systemMessage = new SystemMessage("我叫小特, 是比特教育研发的一款智能AI助手, 擅长Java 和 C++ 语言");
//        UserMessage userMessage = new UserMessage(message);
//        Prompt prompt = new Prompt(systemMessage, userMessage);
//        ChatResponse response = chatModel.call(prompt);
//        return response.getResult().getOutput().getText();
//    }
//
//    @RequestMapping(value = "/stream", produces = "text/html;charset=utf-8")
//    public Flux<String> stream(String message){
//        Prompt prompt = new Prompt(message);
//        Flux<ChatResponse> response = chatModel.stream(prompt);
//        return response.map(x->x.getResult().getOutput().getText());
//    }


}
